package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.LoanRepayPlanDao;
import com.fdb.efp.nls.service.domain.LoanRepayPlan;
import com.fdb.efp.nls.service.facade.LoanRepayPlanService;
import com.fdb.efp.loan.service.vo.LoanRepayPlanVO;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service("accLoanRepayPlanService")
/**
 * 还款计划
 * 
 * @description:TODO
 * @date:2018年12月29日 下午3:21:58
 * @author:cenyj
 */
public class LoanRepayPlanServiceImpl implements LoanRepayPlanService, FrameworkService {
	private static Logger logger = LoggerFactory.getLogger(BatCircleaccServiceImpl.class);

	@Autowired
	private LoanRepayPlanDao loanRepayPlanDao;

	/**
	 * 
	 * 根據马上同步过来的临时表数据修改還款計劃 还款计划
	 * 
	 * @param taskNo
	 * @return
	 * @date:2018年12月27日 下午8:35:23
	 * @author:cenyj
	 * @throws Exception
	 */
	public boolean batchUpdateLoanRepayPlanFromMaTxt() throws Exception {
		boolean rs = false;

		return rs;
	}

	/**
	 * 新增操作 先查根据借据编号去查询loan_repay_plan表是否有还款计划信息，没有则新增，有则修改
	 */
	public int insert(LoanRepayPlan loanRepayPlan) {
		logger.debug("当前新增数据为:" + loanRepayPlan.getRefNbr());
		int num = 0;
		try {
			num = loanRepayPlanDao.insert(loanRepayPlan);
		} catch (Exception e) {
			logger.error("新增数据发生异常!流水号为：" + loanRepayPlan.getRefNbr(), e);
			num = -1;
		}
		logger.debug("当前新增数据流水号为：" + loanRepayPlan.getRefNbr() + "当前新增数据条数为:" + num);
		return num;
	}

	public int insertSelective(LoanRepayPlan loanRepayPlan) {
		logger.debug("当前新增数据为:" + loanRepayPlan.getRefNbr());
		int num = 0;
		try {
			num = loanRepayPlanDao.insert(loanRepayPlan);
		} catch (Exception e) {
			logger.error("新增数据发生异常!流水號為：" + loanRepayPlan.getRefNbr(), e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByRefNbrAndTerm(LoanRepayPlan loanRepayPlan) {
		logger.debug("当前删除数据条件为:流水号" + loanRepayPlan.getRefNbr() + "期数：" + loanRepayPlan.getTerm());
		int num = 0;
		try {
			num = loanRepayPlanDao.deleteByRefNbrAndTerm(loanRepayPlan);
		} catch (Exception e) {
			logger.error("删除数据发生异常!:流水号" + loanRepayPlan.getRefNbr() + "期数：" + loanRepayPlan.getTerm(), e);
			num = -1;
		}
		logger.debug("根据条件:流水号" + loanRepayPlan.getRefNbr() + "期数：" + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	public int updateByPkRefNbrAndTerm(LoanRepayPlan loanRepayPlanUpdate) {
		logger.debug("当前修改数据为:借據號" + loanRepayPlanUpdate.getRefNbr() + "借据期数：" + loanRepayPlanUpdate.getTerm());
		int num = 0;
		try {
			num = loanRepayPlanDao.updateByPkRefNbrAndTerm(loanRepayPlanUpdate);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:流水号" + loanRepayPlanUpdate.getRefNbr() + "借据期数：" + loanRepayPlanUpdate.getTerm() + "修改的数据条数为" + num);
		return num;
	}

	@Override
	public LoanRepayPlanVO getLoanRepayPlanByRefNbrAndMaxTerm(LoanRepayPlanVO loanRepayPlanVo) {
		logger.debug("当前查询参数信息为:" + loanRepayPlanVo);
		try {
			LoanRepayPlan queryLoanRepayPlan = new LoanRepayPlan();
			beanCopy(loanRepayPlanVo, queryLoanRepayPlan);
			queryLoanRepayPlan = loanRepayPlanDao.getLoanRepayPlanByRefNbrAndMaxTerm(queryLoanRepayPlan);
			if (Objects.nonNull(queryLoanRepayPlan)) {
				// beanCopy(loanRepayPlanVo, queryLoanRepayPlan);
				LoanRepayPlanVO outLoanRepayPlanVO = beanCopy(queryLoanRepayPlan, new LoanRepayPlanVO());
				logger.debug("当前查询结果为:" + outLoanRepayPlanVO.toString());
				return outLoanRepayPlanVO;
			} else {
				logger.debug("当前查询结果为空!");
			}

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<LoanRepayPlanVO> queryAllLoanRepayPlan(LoanRepayPlanVO loanRepayPlanVO) {
		logger.debug("当前查询以下数据信息的参数信息为:");
		LoanRepayPlan queryLoanRepayPlan = new LoanRepayPlan();
		beanCopy(loanRepayPlanVO, queryLoanRepayPlan);
		List<LoanRepayPlan> loanRepays = loanRepayPlanDao.queryAllLoanRepayPlan(queryLoanRepayPlan);
		logger.debug("当前查询以下数据信息的结果集数量为:" + loanRepays.size());
		List<LoanRepayPlanVO> list = null;
		try {
			list = (List<LoanRepayPlanVO>) beansCopy(loanRepays, LoanRepayPlanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	@Override
	public int insert(LoanRepayPlanVO loanRepayPlan) {
		logger.debug("当前新增数据为:" + loanRepayPlan.getRefNbr());
		int num = 0;
		try {
			LoanRepayPlan queryLoanRepayPlan = new LoanRepayPlan();
			beanCopy(loanRepayPlan, queryLoanRepayPlan);
			num = loanRepayPlanDao.insert(queryLoanRepayPlan);
		} catch (Exception e) {
			logger.error("新增数据发生异常!流水号为：" + loanRepayPlan.getRefNbr(), e);
			num = -1;
		}
		logger.debug("当前新增数据流水号为：" + loanRepayPlan.getRefNbr() + "当前新增数据条数为:" + num);
		return num;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LoanRepayPlanVO> getBankRepayPlanListByRefNbr(LoanRepayPlanVO loanRepayPlanVO) {
		logger.debug("当前查询以下数据信息的参数信息为:");
		LoanRepayPlan queryLoanRepayPlan = new LoanRepayPlan();
		beanCopy(loanRepayPlanVO, queryLoanRepayPlan);
		List<LoanRepayPlan> loanRepays = loanRepayPlanDao.getBankRepayPlanListByRefNbr(queryLoanRepayPlan);
		logger.debug("当前查询以下数据信息的结果集数量为:" + loanRepays.size());
		List<LoanRepayPlanVO> list = null;
		try {
			list = (List<LoanRepayPlanVO>) beansCopy(loanRepays, LoanRepayPlanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	@Override
	public LoanRepayPlanVO getLoanRepayPlanByRefNbrAndTerm(LoanRepayPlanVO loanRepayPlanVo) {
		logger.debug("当前查询参数信息为:" + loanRepayPlanVo);
		try {
			LoanRepayPlan queryLoanRepayPlan = new LoanRepayPlan();
			beanCopy(loanRepayPlanVo, queryLoanRepayPlan);
			// queryLoanRepayPlan =
			// loanRepayPlanDao.getLoanRepayPlanByRefNbrAndMaxTerm(queryLoanRepayPlan);
			queryLoanRepayPlan = loanRepayPlanDao.getLoanRepayPlanByRefNbrAndTerm(queryLoanRepayPlan);
			if (Objects.nonNull(queryLoanRepayPlan)) {
				// beanCopy(loanRepayPlanVo, queryLoanRepayPlan);
				LoanRepayPlanVO outLoanRepayPlanVO = beanCopy(queryLoanRepayPlan, new LoanRepayPlanVO());
				logger.debug("当前查询结果为:" + outLoanRepayPlanVO.toString());
				return outLoanRepayPlanVO;
			} else {
				logger.debug("当前查询结果为空!");
			}

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public int updateByPkRefNbrAndTerm(LoanRepayPlanVO loanRepayPlanVO) {
		logger.debug("当前修改数据为:借據號" + loanRepayPlanVO.getRefNbr() + "借据期数：" + loanRepayPlanVO.getTerm());
		int num = 0;
		try {
			LoanRepayPlan queryLoanRepayPlan = new LoanRepayPlan();
			beanCopy(loanRepayPlanVO, queryLoanRepayPlan);
			num = loanRepayPlanDao.updateByPkRefNbrAndTerm(queryLoanRepayPlan);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:流水号" + loanRepayPlanVO.getRefNbr() + "借据期数：" + loanRepayPlanVO.getTerm() + "修改的数据条数为" + num);
		return num;
	}

	@Override
	public int updateByPkRefNbrAndStatus(LoanRepayPlanVO loanRepayPlanVO) {
		logger.debug("当前修改数据为:借據號" + loanRepayPlanVO.getRefNbr() + "借据期数：" + loanRepayPlanVO.getTerm());
		int num = 0;
		try {
			LoanRepayPlan queryLoanRepayPlan = new LoanRepayPlan();
			beanCopy(loanRepayPlanVO, queryLoanRepayPlan);
			num = loanRepayPlanDao.updateByPkRefNbrAndStatus(queryLoanRepayPlan);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:流水号" + loanRepayPlanVO.getRefNbr() + "借据期数：" + loanRepayPlanVO.getStatus() + "修改的数据条数为" + num);
		return num;
	}

	@Override
	public int deleteByRefNbrAndTerm(LoanRepayPlanVO loanRepayPlan) {
		logger.debug("当前删除数据条件为:流水号" + loanRepayPlan.getRefNbr() + "期数：" + loanRepayPlan.getTerm());
		int num = 0;
		try {
			LoanRepayPlan queryLoanRepayPlan = new LoanRepayPlan();
			beanCopy(loanRepayPlan, queryLoanRepayPlan);
			num = loanRepayPlanDao.deleteByRefNbrAndTerm(queryLoanRepayPlan);
		} catch (Exception e) {
			logger.error("删除数据发生异常!:流水号" + loanRepayPlan.getRefNbr() + "期数：" + loanRepayPlan.getTerm(), e);
			num = -1;
		}
		logger.debug("根据条件:流水号" + loanRepayPlan.getRefNbr() + "期数：" + "删除的数据条数为" + num);
		return num;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LoanRepayPlanVO> qryLoanRepayPlanByLoanNo(LoanRepayPlanVO loanRepayPlanVo) {
		List<LoanRepayPlanVO> list = null;
		logger.debug("根据借据号分页查询还款计划信息开始:");
		LoanRepayPlan qryLoanRepayPlan = new LoanRepayPlan();
		beanCopy(loanRepayPlanVo, qryLoanRepayPlan);
		List<LoanRepayPlan> loanRepayPlanList = loanRepayPlanDao.qryLnRyPlanByLoanNoByPage(qryLoanRepayPlan);
		logger.debug("根据借据号查询数据信息的结果集数量为:" + loanRepayPlanList.size());
		try {
			pageSet(loanRepayPlanList, qryLoanRepayPlan);
			list = (List<LoanRepayPlanVO>) beansCopy(loanRepayPlanList, LoanRepayPlanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 
	 * 通过借据号、违约标志查询还款计划信息 <br>
	 * 0.1:ludayong:2019年3月5日 下午9:56:23:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月5日 下午9:56:23
	 * @date 2019年3月5日 下午9:56:23
	 * @version 0.1
	 */
	@Override
	public List<LoanRepayPlanVO> queryLoanRepayPlanByLoanNoAndOverdueFlag(LoanRepayPlanVO loanRepayPlanVo) {
		List<LoanRepayPlanVO> list = null;
		logger.debug("根据借据号分页查询还款计划信息开始:");
		LoanRepayPlan qryLoanRepayPlan = new LoanRepayPlan();
		beanCopy(loanRepayPlanVo, qryLoanRepayPlan);
		List<LoanRepayPlan> loanRepayPlanList = loanRepayPlanDao.queryLoanRepayPlanByLoanNoAndOverdueFlag(qryLoanRepayPlan);
		logger.debug("根据借据号查询数据信息的结果集数量为:" + loanRepayPlanList.size());
		try {
			list = (List<LoanRepayPlanVO>) beansCopy(loanRepayPlanList, LoanRepayPlanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<LoanRepayPlanVO> queryPageByRefNbr(LoanRepayPlanVO loanRepayPlanVO, Integer offset, Integer limit) {

		List<LoanRepayPlan> loanRepayPlans = this.loanRepayPlanDao.queryPageByRefNbr(loanRepayPlanVO.getRefNbr(), new RowBounds(offset, limit));
		if (loanRepayPlans != null || loanRepayPlans.size() > 0) {
			try {
				return (List<LoanRepayPlanVO>) beansCopy(loanRepayPlans, LoanRepayPlanVO.class);
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("数据转换出现异常!", e);
			}
		}
		return null;
	}

	@Override
	public Integer queryCountByRefNbr(LoanRepayPlanVO loanRepayPlanVO) {
		return this.loanRepayPlanDao.queryCountByRefNbr(loanRepayPlanVO.getRefNbr());
	}
	/**
	 * 
	 * 批量新增还款计划信息 <br>
	 * 0.1:ludayong:2019年3月11日 下午9:34:07:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月11日 下午9:34:07
	 * @date 2019年3月11日 下午9:34:07
	 * @version 0.1
	 */
	@Override
	public int batchInsertLoanRepayPlan(List<LoanRepayPlanVO> addList) {
		logger.debug("当前新增数据条数为:" + addList.size());
		List<LoanRepayPlan> loanRepayPlanList = new ArrayList<LoanRepayPlan>();
		int num = 0;
		try {
			num = loanRepayPlanDao.batchInsertLoanRepayPlan(loanRepayPlanList);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}
	
	@Override
	public int batchInsert(List<LoanRepayPlanVO> loanRepayPlanVOList) {
		logger.debug("批量新增loan_repay_plan还款计划表,当前新增数据条数为:" + loanRepayPlanVOList.size());
		int num = 0;
		try {
			num = loanRepayPlanDao.batchInsert(loanRepayPlanVOList);
		} catch (Exception e) {
			logger.error("批量新增loan_repay_plan还款计划表发生异常!流水号为：" + loanRepayPlanVOList.get(0).getRefNbr(), e);
			num = -1;
		}
		logger.debug("批量新增loan_repay_plan还款计划表,当前新增数据流水号为：" + loanRepayPlanVOList.get(0).getRefNbr() + "当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 
	 * 批量更新还款明细信息 <br>
	 * 0.1:ludayong:2019年3月8日 下午2:37:18:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月8日 下午2:37:18
	 * @date 2019年3月8日 下午2:37:18
	 * @version 0.1
	 */
	@Override
	public int batchUpdateLoanRepayPlan(List<LoanRepayPlanVO> updateList) {
		logger.debug("批量更新loan_repay_plan还款计划表，当前修改数据为:" + updateList.size() + "条");
		List<LoanRepayPlan> loanRepayPlanList = new ArrayList<LoanRepayPlan>();
		int num = 0;
		try {
			loanRepayPlanList = (List<LoanRepayPlan>) beansCopy(updateList, LoanRepayPlan.class);
			num = loanRepayPlanDao.batchUpdateLoanRepayPlan(loanRepayPlanList);
		} catch (Exception e) {
			logger.error("批量更新loan_repay_plan还款计划表发生异常!", e);
			num = -1;
		}
		logger.debug("批量更新loan_repay_plan还款计划表，修改的数据条数为" + num);
		return num;
	}
		/**
	 * 更新或者插入还款计划: <br>
	 *
	 * 0.1:caoxin:2019/5/15 14:59: TODO: <br>
	 * @author caoxin
	 * @return
	 * @since 2019/5/15 14:59
	 * @date 2019/5/15 14:59
	 * @version 0.1
	 */
	@Override
	public int batchInsertOrUpdateLoanRepayPlan(List<LoanRepayPlanVO> LoanRepayPlanVOs) {
		List<LoanRepayPlan> loanRepayPlans = new ArrayList<LoanRepayPlan>();
		int num = 0;
		try {
			loanRepayPlans = (List<LoanRepayPlan>) beansCopy(LoanRepayPlanVOs, LoanRepayPlan.class);
			num = loanRepayPlanDao.insertOrUpdateBdMoneyDraw(loanRepayPlans);
			String num_msg = "【还款计划表】插入或更新数据处理结果:" + num;
			logger.info(num_msg, "message{}");
		} catch (Exception e) {
			String msg2 = "【还款计划表】插入或更新数据出现异常:" + e;
			logger.error(msg2, "message{}");
			num = -1;
		}
		return num;
	}
//	
//		@Override
//	public List<LoanRepayPlanVO>  queryMinOverdueTerm(String bizDate) {
//		logger.debug("当前查询以下数据信息的参数信息为:");
//		List<LoanRepayPlan> loanRepayPlanVO = this.loanRepayPlanDao.queryMinOverdueTerm(bizDate);
//		logger.debug("当前查询以下数据信息的结果集数量为:" + loanRepayPlanVO.size());
//		List<LoanRepayPlanVO> list = null;
//		try {
//			list = (List<LoanRepayPlanVO>) beansCopy(loanRepayPlanVO, LoanRepayPlanVO.class);
//		} catch (Exception e) {
//			logger.error("数据转换出现异常!", e);
//		}
//		return list;
//	}
//	
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:根据产品查询数据
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响当前产品实际业务
//	@Override
//	public List<LoanRepayPlanVO> queryCreditReportionData(List<String> prdInfoIds, String batchDate) {
//
//		//根据产品查询数据
//		List<LoanRepayPlan> list=loanRepayPlanDao.queryCreditReportingData(prdInfoIds,batchDate);
//		try {
//			return (List<LoanRepayPlanVO>) beansCopy(list, LoanRepayPlanVO.class);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return null;
//	}
//	/**
//	 * 更新操作
//	 */
	@Override
	public int updateByLoanRepayPlanByRefNbrAndTerm(LoanRepayPlanVO loanRepayPlanVO) {
		logger.debug("当前修改数据为:借據號" + loanRepayPlanVO.getRefNbr() + "借据期数：" + loanRepayPlanVO.getTerm());
		int num = 0;
		try {
			LoanRepayPlan udpLoanRepayPlan = new LoanRepayPlan();
			beanCopy(loanRepayPlanVO, udpLoanRepayPlan);
			num = loanRepayPlanDao.updateByLoanRepayPlanByRefNbrAndTerm(udpLoanRepayPlan);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:流水号" + loanRepayPlanVO.getRefNbr() + "借据期数：" + loanRepayPlanVO.getTerm() + "修改的数据条数为" + num);
		return num;
	}
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:查询当前期限
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响当前产品实际业务
//	@Override
//	public int queryCurrentTerm(String batchDate, String billNo) {
//		int result = 0;
//		try {
//			result = loanRepayPlanDao.queryCurrentTerm(batchDate, billNo);
//		}catch (Exception e) {
//			e.printStackTrace();
//		}
//
//		return result;
//	}
//	//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:根据产品查询数据
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响当前产品实际业务
//	@Override
//	public List<LoanRepayPlanVO> queryRepayPlanByRefNbrAndStatus(LoanRepayPlanVO loanRepayPlanVO) {
//		//根据产品查询数据
//		List<LoanRepayPlan> list=loanRepayPlanDao.queryRepayPlanByRefNbrAndStatus(loanRepayPlanVO);
//		try {
//			return (List<LoanRepayPlanVO>) beansCopy(list, LoanRepayPlanVO.class);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return null;
//	}
//

	@Override
	public int deleteByLoanNo(String loanNo) {
		int num = 0;
		logger.debug("当前删除数据条件——借据编号为：" + loanNo );
		try {
			num = loanRepayPlanDao.deleteByRefNbr(loanNo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!借据编号为：" + loanNo, e);
			num = -1;
		}
		logger.debug("根据借据编号" + loanNo + "删除的数据条数为：" + num);
		return num;
	}

	@Override
	public Integer queryCurrentTerm(String batchDate, String billNo) {
		int result = 0;
		try {
			result = loanRepayPlanDao.queryCurrentTerm(batchDate, billNo);
		}catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	@Override
	public List<LoanRepayPlanVO> queryRepayPlanByRefNbrAndStatus(LoanRepayPlanVO loanRepayPlanVO) {
		//根据产品查询数据
		List<LoanRepayPlan> list=loanRepayPlanDao.queryRepayPlanByRefNbrAndStatus(loanRepayPlanVO);
		try {
			return (List<LoanRepayPlanVO>) beansCopy(list, LoanRepayPlanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 日初借据分期计划临时表数据到分期计划表有数据则更新，无则新增  <br>
	 * 0.1: weijj:2019年5月11日 下午4:38:57:新增<br>
	 * @author  weijj
	 * @since 2019年5月11日 下午4:38:57
	 * @date 2019年5月11日 下午4:38:57
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public int insertOrUpdateLoanRepayPlan(List<LoanRepayPlanVO> list) {
		// TODO Auto-generated method stub
		LocalDate today = LocalDate.now();
		String msg1 = "【分期计划表】数据同步开始..." + today;
		logger.info(msg1, "message{}");
		List<LoanRepayPlan> loanRepayPlanList = new ArrayList<LoanRepayPlan>();
		int num = 0;
		try {
			try {
				loanRepayPlanList = (List<LoanRepayPlan>) beansCopy(list, LoanRepayPlan.class);
				num = loanRepayPlanDao.insertOrUpdateLoanRepayPlan(loanRepayPlanList);
				String num_msg = "【分期计划表】插入或更新数据处理结果:" + num;
				logger.info(num_msg, "message{}");
			} catch (Exception e) {
				String msg2 = "【分期计划表】插入或更新数据出现异常:" + e;
				logger.error(msg2, "message{}");
				num = -1;
				list = null;
				loanRepayPlanList = null;
			}
		}finally {
			list = null;
			loanRepayPlanList = null;
		}
		return num;
	}

	@Override
	public List<LoanRepayPlanVO> qryAllByLoanNo(String loanNo) {
		List<LoanRepayPlanVO> list = null;
		logger.debug("查询还款计划开始，借据号：" +loanNo);
		List<LoanRepayPlan> loanRepayPlans = loanRepayPlanDao.qryAllByLoanNo(loanNo);
		logger.debug("根据借据号查询数据信息的结果集数量为:" + loanRepayPlans.size());
		try {
			list = (List<LoanRepayPlanVO>) beansCopy(loanRepayPlans, LoanRepayPlanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<LoanRepayPlanVO> queryRepayPlanByRefNbrAndIsOverDue(LoanRepayPlanVO loanRepayPlanVO){
		//根据产品查询数据
		List<LoanRepayPlan> list=loanRepayPlanDao.queryRepayPlanByRefNbrAndIsOverDue(loanRepayPlanVO);
		try {
			return (List<LoanRepayPlanVO>) beansCopy(list, LoanRepayPlanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<LoanRepayPlanVO> queryRepayPlansByRefNbr(List<String> refNbrs) {
		List<LoanRepayPlan> list=loanRepayPlanDao.queryRepayPlansByRefNbr(refNbrs);
		try {
			return (List<LoanRepayPlanVO>) beansCopy(list, LoanRepayPlanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public int fixInitTerm(String prdId) {
		return loanRepayPlanDao.fixInitTerm(prdId);
	}

	@Override
	public List<LoanRepayPlanVO> queryMinOverdueStmtDates(List<String> list) {
		List<LoanRepayPlan> loanRepayPlans = this.loanRepayPlanDao.queryMinOverdueStmtDates(list);
		if (loanRepayPlans == null || loanRepayPlans.isEmpty()) {
			return new ArrayList<>();
		}
		try {
			return (List<LoanRepayPlanVO>) beansCopy(loanRepayPlans, LoanRepayPlanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
			logger.info("转换数据出错：",e);
		}
		return new ArrayList<>();

	}

	@Override
	public int insertOrUpdatePsd(List<LoanRepayPlanVO> list) throws Exception {
		return this.loanRepayPlanDao.insertOrUpdatePsd((List<LoanRepayPlan>) beansCopy(list,LoanRepayPlan.class));
	}

    @Override
    public int insertOrUpdateYed(List<LoanRepayPlanVO> list) throws Exception {
        return this.loanRepayPlanDao.insertOrUpdateYed((List<LoanRepayPlan>) beansCopy(list,LoanRepayPlan.class));
    }
    public List<LoanRepayPlanVO> getLoanRepayPlanByRefNbrAndStatus(LoanRepayPlanVO loanRepayPlanBy){
        //根据产品查询数据
        LoanRepayPlan loanRepayPlan = new LoanRepayPlan();
        loanRepayPlan.setRefNbr(loanRepayPlanBy.getRefNbr());
        loanRepayPlan.setStatus(loanRepayPlanBy.getStatus());
        List<LoanRepayPlan> list=loanRepayPlanDao.getLoanRepayPlanByRefNbrAndStatus(loanRepayPlan);
        try {
            return (List<LoanRepayPlanVO>) beansCopy(list, LoanRepayPlanVO.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

	/**
	 * 需求编号：【2020D1309】（业务提的需求编号）
	 * 问题编号：【xxxxxxx】（若不是因为修复问题而新增该类，则留空）
	 * 开发人员：wanglaisheng
	 * 创建日期：2020年11月23日
	 * 功能描述：通过借据号查询还款计划（注意：不包含缩期部分数据）
	 */
	@Override
	public List<LoanRepayPlanVO> getPlanByPKWithoutCancelStatusByPage(LoanRepayPlanVO vo){
		List<LoanRepayPlanVO> list = null;
		logger.debug("根据借据号分页查询还款计划信息开始:");
		LoanRepayPlan qryLoanRepayPlan = new LoanRepayPlan();
		beanCopy(vo, qryLoanRepayPlan);
		List<LoanRepayPlan> loanRepayPlanList = loanRepayPlanDao.getPlanByPKWithoutCancelStatusByPage(qryLoanRepayPlan);
		logger.debug("根据借据号查询数据信息的结果集数量为:" + loanRepayPlanList.size());
		try {
			pageSet(loanRepayPlanList, qryLoanRepayPlan);
			list = (List<LoanRepayPlanVO>) beansCopy(loanRepayPlanList, LoanRepayPlanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
}
